#ifndef GATE_CONNECTOR_EVENT_HANDLER
#define GATE_CONNECTOR_EVENT_HANDLER
#include "net_module.h"
#include "gate_event_handler.h"

namespace utility
{
namespace network
{
    struct gate_protocol_header;
    class gate_connector_impl;

    class gate_connector_event_handler :  public gate_event_handler
    {
    public:
        typedef gate_connector_event_handler * pointer;

    public:
        gate_connector_event_handler(gate_connector_impl * );
        ~gate_connector_event_handler(void);


        // handler when receive msg
        virtual void on_receive(const char * message, uint32 message_length);

        // handler when connection disconnected
        virtual void on_disconnected();

        // handler when any error occurred
        virtual void on_error(int32 error_code, const char * error_message);

        virtual void broadcast(std::set<gate_client_session *> & sessions, void * message, size_t message_length){}

        void set_connector(const connector * c);

    private:
        virtual session * _get_session();

        void _establish_connection(gate_protocol_header * header);

        virtual session_mgr * _get_session_mgr();

        void _broadcast(gate_broadcast_header *, char * buf, size_t buf_size);

    private:
        utility::network::connector * connector_;
        gate_connector_impl * gate_connector_;
        
    };

}
}



#endif // endif of GATE_CONNECTOR_EVENT_HANDLER
